package com.aaa.sso.controller;

import com.aaa.common.bo.TreeNode;
import com.aaa.common.util.Result;
import com.aaa.sso.service.RemoteUserService;
import com.aaa.sso.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: YuXin
 * @Date : Created in 2020/11/12 16:58
 * @ClassName : UserLoginAndCheckToken
 * @Description :
 * @Package_Name : com.aaa.sso.controller
 */
@RestController
@RequestMapping("ssoTokenController")
public class UserLoginAndCheckTokenController {

    @Autowired
    private UserService userService;

    @Autowired
    private RemoteUserService remoteUserService;
    /**
     * 用户登录功能
     *
     * @param userName
     * @param password
     */
    @GetMapping("userLogin")
    public Map userLogin(String userName, String password) {
        Result result = userService.userLogin(userName, password);
        String token = (String) result.getData();
        List<TreeNode> treeNodeList = remoteUserService.selectMenuTreeByToken(token);
        Map map = new HashMap();
        map.put("token", token);
        map.put("treeNodeList", treeNodeList);
        return map;
    }

    /**
     * 检查token
     *
     * @param token @RequestParam("accessToken")
     */
    @GetMapping("checkToken")
    public boolean checkToken(@RequestParam("accessToken") String token) {
        return userService.checkToken(token);
    }

}
